<?php
/**
 * 附件上传
 */

class Model_Attachment {
	
	/**
	 * 删除附件
	 *
	 * @param int $attachId        	
	 */
	public function delete_Attachment($attachId) {
		$DB_Attachment = new DB_Attachments ();
		$types = $DB_Attachment->loadInfo ( 'attach_type,resource_id', "attach_id={$attachId}" );
		$return = $DB_Attachment->delete ( "attach_id={$attachId}" );
		
		if ($return) {
			// 清空与附件相关联的数据
			$type = $types ['attach_type'];
			$resource_id = $types ['resource_id'];
			
			switch ($type) {
				case "news" :
					$DB_News = new DB_News ();
					$DB_News->update(array('news_img'=>''), "id={$resource_id}");
				break;
			}
		}
	}
}
?>